class BillingOrdersController < ApplicationController
  # ssl_required :new, :destroy
  # ssl_allowed  :index
  
  # GET /billing_orders
  # GET /billing_orders.xml
  def index
    @billing_orders = BillingOrder.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @billing_orders }
    end
  end

  # GET /billing_orders/1
  # GET /billing_orders/1.xml
  def show
    @billing_order = BillingOrder.find(params[:id])
    @billing_transactions = BillingTransaction.find_all_by_order_id(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @billing_order }
    end
  end

  # GET /billing_orders/new
  # GET /billing_orders/new.xml
  def new
    @billing_order = BillingOrder.new
    
    @billing_account = BillingAccount.find(:all)

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @billing_order }
    end
  end

  # GET /billing_orders/1/edit
  def edit
    @billing_order = BillingOrder.find(params[:id])
  end

  # POST /billing_orders
  # POST /billing_orders.xml
  def create
    params[:billing_order][:ip_address] = request.remote_ip
    
    @billing_order = BillingOrder.new(params[:billing_order])
    
    @billing_account = BillingAccount.find(:all)
    respond_to do |format|
      if @billing_order.save
        flash[:notice] = 'BillingOrder was successfully created.'
        format.html { redirect_to(@billing_order) }
        format.xml  { render :xml => @billing_order, :status => :created, :location => @billing_order }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @billing_order.errors, :status => :unprocessable_entity }
      end
    end
  end

  # # PUT /billing_orders/1
  # # PUT /billing_orders/1.xml
  # def update
  #   @billing_order = BillingOrder.find(params[:id])
  # 
  #   respond_to do |format|
  #     if @billing_order.update_attributes(params[:billing_order])
  #       flash[:notice] = 'BillingOrder was successfully updated.'
  #       format.html { redirect_to(@billing_order) }
  #       format.xml  { head :ok }
  #     else
  #       format.html { render :action => "edit" }
  #       format.xml  { render :xml => @billing_order.errors, :status => :unprocessable_entity }
  #     end
  #   end
  # end

  # DELETE /billing_orders/1
  # DELETE /billing_orders/1.xml
  def destroy
    @billing_order = BillingOrder.find(params[:id])
    @billing_order.destroy

    respond_to do |format|
      format.html { redirect_to(billing_orders_url) }
      format.xml  { head :ok }
    end
  end
end
